package LinkedList;

class ListNode1 {
    int val;
    ListNode1 next;
    ListNode1() {}
    ListNode1(int val) { this.val = val; }
    ListNode1(int val, ListNode1 next) { this.val = val; this.next = next; }
 }
//单链表翻转
class Solution2 {
    public ListNode1 reverseList(ListNode1 head) {
        if(head==null||head.next==null){
            return head;
        }
        ListNode1 pre = null;
        ListNode1 cur = head;
        ListNode1 next = cur.next;
        while (next.next!=null){
            pre = cur;
            cur = next;
            next = next.next;
            cur.next = pre;
        }
        next.next = cur;
        head.next = null;
        return next;
    }
}